//
//  EFOrderUserInfoCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/11.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFOrderUserInfoCell.h"
#import "EFOrderUserInfoItem.h"

@interface EFOrderUserInfoCell ()
@property (strong, nonatomic) UILabel *nameAndPhoneLabel;
@property (strong, nonatomic) UILabel *addressLabel;
@property (strong, nonatomic) UIView *line;
@property (strong, nonatomic) UIImageView *moreIV;
@end

@implementation EFOrderUserInfoCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self.contentView addSubview:self.nameAndPhoneLabel];
    [self.contentView addSubview:self.addressLabel];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.moreIV];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.line.left = 20;
    self.line.bottom = self.height;
    
    self.moreIV.top = (self.height - self.moreIV.height)/2;
    self.moreIV.left = kScreenWidth - self.moreIV.width - 20;
}

- (void)setObject:(EFOrderUserInfoItem *)item{
    self.nameAndPhoneLabel.text = [NSString stringWithFormat:@"%@    %@",item.name,item.phone];
    [self.nameAndPhoneLabel sizeToFit];
    self.nameAndPhoneLabel.left = 20;
    self.nameAndPhoneLabel.top = 15;
    
    self.addressLabel.text = [NSString stringWithFormat:@"%@%@",item.addr,item.addr_detail];
    self.addressLabel.width = kScreenWidth - 2*20;
    [self.addressLabel sizeToFit];
    self.addressLabel.left = 20;
    self.addressLabel.top = self.nameAndPhoneLabel.bottom + 1;
    if(item.showMore){
        self.moreIV.hidden = NO;
    }else{
        self.moreIV.hidden = YES;
    }
    
  }

+ (CGFloat)cellHeight:(EFOrderUserInfoItem *)item{
    CGFloat height = 46;
    
    NSString *addressInfo = [NSString stringWithFormat:@"%@%@",item.addr,item.addr_detail];
    UILabel *tempLabel = [[UILabel alloc] init];
    tempLabel.font = [UIFont systemFontOfSize:13];
    tempLabel.numberOfLines = 0;
    tempLabel.text = addressInfo;
    
    tempLabel.width = kScreenWidth - 2*20;
    [tempLabel sizeToFit];
    
    CGFloat labelHeight = tempLabel.height;
    
    return height + labelHeight;
}

- (UILabel *)nameAndPhoneLabel{
    if (!_nameAndPhoneLabel) {
        _nameAndPhoneLabel = [[UILabel alloc] init];
        _nameAndPhoneLabel.font = [UIFont systemFontOfSize:13];
        _nameAndPhoneLabel.textColor = kBlack333;
    }
    return _nameAndPhoneLabel;
}

- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.font = [UIFont systemFontOfSize:13];
        _addressLabel.textColor = kBlack333;
        _addressLabel.numberOfLines = 0;
    }
    return _addressLabel;
}

- (UIView *)line{
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 2*20, 1)];
        _line.backgroundColor = RGBCOLOR(0xececec);
    }
    return _line;
}

-(UIImageView *)moreIV{
    if(_moreIV == NULL){
        _moreIV = [[UIImageView alloc ] initWithFrame:CGRectMake(0, 0, 20, 20)];
        [_moreIV setImage:IMG(@"more_icon_me_default")];
    }
    return _moreIV;
}

@end
